<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Symbol类型</title>
</head>
<body>
  <script>
    /**
     * 1. 作为唯一标示，避免命名冲突
     * 2. Symbol对象不可遍历，可以作为私有变量
    */
    
    // 1. 作为唯一标示，避免命名冲突
    const cs1 = Symbol('cs');
    const cs2 = Symbol('cs');
    console.log(cs1 === cs2); // false

    const obj = {
      [Symbol('cs')]: 90,
      [Symbol('cs')]: 96,
    }
    // 获取属性key,下面的方法都不可取
    console.log(Object.keys(obj));  // []
    console.log(Object.getOwnPropertyNames(obj)); // []

    // 获取属性key,只能使用Object.getOwnPropertySymbols()
    const keys = Object.getOwnPropertySymbols(obj);
    console.log('keys', keys); // [Symbol(cs), Symbol(cs)]
    const values = keys.map(key => obj[key]);
    console.log('values', values); // [90, 96]
  </script>
</body>
</html>